package acm.pta15;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        int n = Integer.valueOf(sc.readLine());
        String l[] = new String[n + 10], r[] = new String[n + 10];
        for (int i = 1; i <= n; i++) {
            String s[] = sc.readLine().split(" ");
            l[i] = s[0];
            r[i] = s[2];
        }
        Arrays.sort(l, 1, n + 1);
        Arrays.sort(r, 1, n + 1);

        if (!l[1].equals("00:00:00"))
            out.println("00:00:00 - " + l[1]);

        for (int i = 2; i <= n; i++) {
            if (!r[i - 1].equals(l[i]))
                out.println(r[i - 1] + " - " + l[i]);
        }
        if (!r[n].equals("23:59:59"))
            out.printf(r[n] + " - 23:59:59");

        out.flush();
        out.close();
    }

    static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
}
